﻿#region

using System.Collections.Generic;
using System.Threading;
using Ink_Master.Bots.InkMaster.BagHandlers;
using Styx.Helpers;
using Styx.Logic.Combat;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;

#endregion

namespace Ink_Master.Bots.InkMaster.Actions
{
    public static class Pigments
    {
        public static List<uint> PigmentList = new List<uint>
                                                   {
                                                       // INKS
                                                       39151,
                                                       //Alabaster Pigment
                                                       39334,
                                                       //Dusky Pigment
                                                       43103,
                                                       //Verdant Pigment
                                                       39338,
                                                       //Golden Pigment
                                                       43104,
                                                       //Burnt Pigment
                                                       39339,
                                                       //Emerald Pigment
                                                       43105,
                                                       //Indigo Pigment
                                                       39340,
                                                       //Violet Pigment
                                                       43106,
                                                       //Ruby Pigment
                                                       39341,
                                                       //Silvery Pigment
                                                       43107,
                                                       //Sapphire Pigment
                                                       39342,
                                                       //Nether Pigment
                                                       43108,
                                                       //Ebon Pigment
                                                       39343,
                                                       //Azure Pigment
                                                       43109,
                                                       //Icy Pigment
                                                       61979,
                                                       //Ashen Pigment
                                                       61980,
                                                       //Burning Embers
                                                   };

        private static int NumOfItemsInBag(uint entry)
        {
            return Lua.GetReturnValues("return GetItemCount (\"" + entry.ToString() + "\")", "fish.lua")[0].ToInt32();
        }

        public static void PigmentsToInk()
        {
            ObjectManager.Update();

            Log.Slog("Starting PigmentsToInk Proc");
            foreach (WoWItem item in ObjectManager.Me.BagItems)
            {
                if (Search.ItemIdFromItemLink(item.ItemLink) == 39343 && item.StackCount >= 2)
                {
                    WoWSpell pig = WoWSpell.FromId(57715);
                    if (SpellManager.CanCast(pig))
                    {
                        WoWMovement.MoveStop();
                        Thread.Sleep(250);
                        while (NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)) >= 2)
                        {
                            SpellManager.Cast(pig);
                            Log.Slog("Inking " + item.Name + "I have " +
                                     NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)));
                            Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                            Thread.Sleep(2500);
                        }
                    }
                }

                else if (Search.ItemIdFromItemLink(item.ItemLink) == 43109 && item.StackCount >= 2)
                {
                    WoWSpell pig1 = WoWSpell.FromId(57716);
                    if (SpellManager.CanCast(pig1))
                    {
                        WoWMovement.MoveStop();
                        Thread.Sleep(250);
                        while (NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)) >= 2)
                        {
                            SpellManager.Cast(pig1);
                            Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                            Thread.Sleep(2500);
                        }
                    }
                }
                else if (Search.ItemIdFromItemLink(item.ItemLink) == 61980 && item.StackCount >= 2)
                {
                    WoWSpell pig2 = WoWSpell.FromId(86005);
                    if (SpellManager.CanCast(pig2))
                    {
                        WoWMovement.MoveStop();
                        Thread.Sleep(250);
                        while (NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)) >= 2)
                        {
                            SpellManager.Cast(pig2);


                            Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                            Thread.Sleep(2500);
                        }
                    }
                }

                else if (Search.ItemIdFromItemLink(item.ItemLink) == 61979 && item.StackCount >= 2)
                {
                    WoWSpell pig3 = WoWSpell.FromId(86004);
                    if (SpellManager.CanCast(pig3))
                    {
                        WoWMovement.MoveStop();
                        Thread.Sleep(250);
                        while (NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)) >= 2)
                        {
                            SpellManager.Cast(pig3);

                            Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                            Thread.Sleep(2500);
                        }
                    }
                }

                else if (Search.ItemIdFromItemLink(item.ItemLink) == 39151 && item.StackCount >= 2)
                {
                    WoWSpell pig4 = WoWSpell.FromId(52738);
                    if (SpellManager.CanCast(pig4))
                    {
                        WoWMovement.MoveStop();
                        Thread.Sleep(250);
                        while (NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)) >= 2)
                        {
                            SpellManager.Cast(pig4);


                            Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                            Thread.Sleep(2500);
                        }
                    }
                }

                else if (Search.ItemIdFromItemLink(item.ItemLink) == 39334 && item.StackCount >= 2)
                {
                    WoWSpell pig5 = WoWSpell.FromId(53462);
                    if (SpellManager.CanCast(pig5))
                    {
                        WoWMovement.MoveStop();
                        Thread.Sleep(250);
                        while (NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)) >= 2)
                        {
                            SpellManager.Cast(pig5);


                            Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                            Thread.Sleep(2500);
                        }
                    }
                }

                else if (Search.ItemIdFromItemLink(item.ItemLink) == 43103 && item.StackCount >= 2)
                {
                    WoWSpell pig6 = WoWSpell.FromId(57703);
                    if (SpellManager.CanCast(pig6))
                    {
                        WoWMovement.MoveStop();
                        Thread.Sleep(250);
                        while (NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)) >= 2)
                        {
                            SpellManager.Cast(pig6);


                            Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                            Thread.Sleep(2500);
                        }
                    }
                }

                else if (Search.ItemIdFromItemLink(item.ItemLink) == 39338 && item.StackCount >= 2)
                {
                    WoWSpell pig7 = WoWSpell.FromId(57704);
                    if (SpellManager.CanCast(pig7))
                    {
                        WoWMovement.MoveStop();
                        Thread.Sleep(250);
                        while (NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)) >= 2)
                        {
                            SpellManager.Cast(pig7);


                            Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                            Thread.Sleep(2500);
                        }
                    }
                }

                else if (Search.ItemIdFromItemLink(item.ItemLink) == 43104 && item.StackCount >= 2)
                {
                    WoWSpell pig8 = WoWSpell.FromId(57706);
                    if (SpellManager.CanCast(pig8))
                    {
                        WoWMovement.MoveStop();
                        Thread.Sleep(250);
                        while (NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)) >= 2)
                        {
                            SpellManager.Cast(pig8);


                            Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                            Thread.Sleep(2500);
                        }
                    }
                }

                else if (Search.ItemIdFromItemLink(item.ItemLink) == 39339 && item.StackCount >= 2)
                {
                    WoWSpell pig9 = WoWSpell.FromId(57707);
                    if (SpellManager.CanCast(pig9))
                    {
                        WoWMovement.MoveStop();
                        Thread.Sleep(250);
                        while (NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)) >= 2)
                        {
                            SpellManager.Cast(pig9);


                            Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                            Thread.Sleep(2500);
                        }
                    }
                }

                else if (Search.ItemIdFromItemLink(item.ItemLink) == 43105 && item.StackCount >= 2)
                {
                    WoWSpell pig10 = WoWSpell.FromId(57708);
                    if (SpellManager.CanCast(pig10))
                    {
                        WoWMovement.MoveStop();
                        Thread.Sleep(250);
                        while (NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)) >= 2)
                        {
                            SpellManager.Cast(pig10);


                            Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                            Thread.Sleep(2500);
                        }
                    }
                }

                else if (Search.ItemIdFromItemLink(item.ItemLink) == 39340 && item.StackCount >= 2)
                {
                    WoWSpell pig11 = WoWSpell.FromId(57709);
                    if (SpellManager.CanCast(pig11))
                    {
                        WoWMovement.MoveStop();
                        Thread.Sleep(250);
                        while (NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)) >= 2)
                        {
                            SpellManager.Cast(pig11);


                            Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                            Thread.Sleep(2500);
                        }
                    }
                }

                else if (Search.ItemIdFromItemLink(item.ItemLink) == 43106 && item.StackCount >= 2)
                {
                    WoWSpell pig12 = WoWSpell.FromId(57710);
                    if (SpellManager.CanCast(pig12))
                    {
                        WoWMovement.MoveStop();
                        Thread.Sleep(250);
                        while (NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)) >= 2)
                        {
                            SpellManager.Cast(pig12);


                            Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                            Thread.Sleep(2500);
                        }
                    }
                }

                else if (Search.ItemIdFromItemLink(item.ItemLink) == 39341 && item.StackCount >= 2)
                {
                    WoWSpell pig13 = WoWSpell.FromId(57711);
                    if (SpellManager.CanCast(pig13))
                    {
                        WoWMovement.MoveStop();
                        Thread.Sleep(250);
                        while (NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)) >= 2)
                        {
                            SpellManager.Cast(pig13);


                            Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                            Thread.Sleep(2500);
                        }
                    }
                }

                else if (Search.ItemIdFromItemLink(item.ItemLink) == 43107 && item.StackCount >= 2)
                {
                    //TODO Can cast spell doesnt seem to work
                    WoWSpell pig14 = WoWSpell.FromId(57712);
                    WoWMovement.MoveStop();
                    Thread.Sleep(250);
                    while (NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)) >= 2)
                    {
                        SpellManager.Cast(pig14);


                        Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                        Thread.Sleep(2500);
                    }
                }

                else if (Search.ItemIdFromItemLink(item.ItemLink) == 39342 && item.StackCount >= 2)
                {
                    WoWSpell pig15 = WoWSpell.FromId(57713);
                    if (SpellManager.CanCast(pig15))
                    {
                        WoWMovement.MoveStop();
                        Thread.Sleep(250);
                        while (NumOfItemsInBag(Search.ItemIdFromItemLink(item.ItemLink)) >= 2)
                        {
                            SpellManager.Cast(pig15);


                            Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                            Thread.Sleep(2500);
                        }
                    }
                }

                else if (Search.ItemIdFromItemLink(item.ItemLink) == 43108 && item.StackCount >= 2)
                {
                    WoWSpell pig16 = WoWSpell.FromId(57714);
                    if (SpellManager.CanCast(pig16))
                    {
                        WoWMovement.MoveStop();
                        Thread.Sleep(250);
                        while (NumOfItemsInBag(item.Entry) >= 2)
                        {
                            SpellManager.Cast(pig16);


                            Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                            Thread.Sleep(2500);
                        }
                    }
                }
            }
        }
    }
}